package com.vegetable.modules.controller.outbound;


import com.alibaba.fastjson.JSON;
import com.vegetable.common.annotation.PreventDuplicateSubmit;
import com.vegetable.common.annotation.SysLog;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.common.utils.R;
import com.vegetable.modules.controller.AbstractController;
import com.vegetable.modules.entity.outbound.SalesOther;
import com.vegetable.modules.service.outbound.ISalesOtherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 其他出库表 前端控制器
 * </p>
 *
 * @author wangruijie
 * @since 2024-04-03
 */
@Slf4j
@RestController
@RequestMapping("/outStorage/salesOther")
@AllArgsConstructor
@Api(value = "其他出库", tags = "其他出库")
public class SalesOtherController extends AbstractController {

    private ISalesOtherService salesOtherService;
    /**
     * 所有其他出库列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "条件查询其他出库列表", notes = "条件查询其他出库列表")
    public R list(@RequestParam Map<String, Object> params){
        log.info("条件查询其他出库列表{}", JSON.toJSONString(params));
        PageUtils page = salesOtherService.queryPage(params);
        return R.data( page);
    }

    /**
     * 详情其他出库
     */
    @SysLog(value = "详情其他出库")
    @GetMapping("/detailSalesOther")
    @ApiOperation(value = "根据id查询详情其他出库", notes = "根据id查询详情其他出库")
    public R detailSalesOther(Long id){
        if (id == null || id == -1){
            return R.fail("订单主键不能为空");
        }
        log.info("根据id查询详情其他出库：{}", JSON.toJSONString(id));
        try {
            return salesOtherService.detailSalesOther(id);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("错误信息:{}",e.getLocalizedMessage());
            return R.fail(e.getMessage());
        }
    }

    /**
     * 新增其他出库
     */
    @SysLog(value = "新增其他出库")
    @PostMapping("/saveSalesOther")
    @ApiOperation(value = "新增其他出库", notes = "新增其他出库")
    public R saveSalesOther(@RequestBody SalesOther salesOther){
        log.info("新增其他出库：{}", JSON.toJSONString(salesOther));
        salesOther.setCreateUserId(getUserId());
        try {
            return salesOtherService.saveSalesOther(salesOther);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("错误信息:{}",e.getLocalizedMessage());
            return R.fail(e.getMessage());
        }
    }
    
    /**
     * 提交其他出库
     */
    @SysLog(value = "提交其他出库")
    @PostMapping("/submitSalesOther")
    @PreventDuplicateSubmit(expireTime = 5)
    @ApiOperation(value = "提交其他出库", notes = "修改其他出库")
    public R submitSalesOther(@RequestBody SalesOther salesOther){
        log.info("提交其他出库：{}", JSON.toJSONString(salesOther));
        salesOther.setCreateUserId(getUserId());
        try {
            return salesOtherService.submitSalesOther(salesOther);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("错误信息:{}",e.getLocalizedMessage());
            return R.fail(e.getMessage());
        }
    }

    /**
     * 删除其他出库
     */
    @SysLog(value = "删除其他出库")
    @GetMapping("/deleteSalesOther")
    @ApiOperation(value = "根据id删除其他出库", notes = "根据id删除其他出库")
    public R deleteSalesOther(Long id){
        log.info("删除其他出库：{}", JSON.toJSONString(id));
        try {
            return salesOtherService.deleteSalesOther(id);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("错误信息:{}",e.getLocalizedMessage());
            return R.fail(e.getMessage());
        }
    }

}
